/**
 * 
 */
package com.monkeyboy.security.filter;

import java.io.IOException;
import java.util.Date;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * @Description 所有的请求都会经过这个过滤器来进行处理
 * @author Gavin<br>
 *         2019年8月24日
 */
//@Component 如果这里不用Component那么就需要配置成为一个bean，通过@Configuration注解，否则无法实例化
public class TimeFilter implements Filter {

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
	 */
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		// TODO Auto-generated method stub
		System.out.println("-filter------------init");

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
	 * javax.servlet.ServletResponse, javax.servlet.FilterChain)
	 */
	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		System.out.println("--filter---------start");
		long start = new Date().getTime();
		chain.doFilter(request, response);
		System.out.println("---服务耗时时间---" + (new Date().getTime() - start));
		System.out.println("--filter---------finish");

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.Filter#destroy()
	 */
	@Override
	public void destroy() {
		System.out.println("-filter--------------destroy");

	}

}
